package com.library.web.controller.library;


import com.library.common.annotation.Log;
import com.library.common.core.controller.BaseController;
import com.library.common.core.domain.AjaxResult;
import com.library.common.core.page.TableDataInfo;
import com.library.common.enums.BusinessType;
import com.library.common.utils.poi.ExcelUtil;
import com.library.domain.MbSignRules;
import com.library.service.IMbSignRulesGiftService;
import com.library.service.IMbSignRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 签到规则 信息操作处理
 *
 * @author null
 * @date 2020-04-23
 * @blame Android Team
 */
@RestController
@RequestMapping("/library/mbSignRules")
public class MbSignRulesController extends BaseController {
    private String prefix = "business/mobile/mbSignRules";

    @Autowired
    private IMbSignRulesService mbSignRulesService;

    @Autowired
    private IMbSignRulesGiftService mbSignRulesGiftService;

    /**
     * 查询签到规则列表
     */
    @PreAuthorize("@ss.hasPermi('library:mbSignRules:list')")
    @GetMapping("/list")
    public TableDataInfo list(MbSignRules mbSignRules) {
        startPage();
        List<MbSignRules> list = mbSignRulesService.selectMbSignRulesList(mbSignRules);
        return getDataTable(list);
    }

    /**
     * 导出签到规则列表
     */
    @PreAuthorize("@ss.hasPermi('library:mbSignRules:export')")
    @Log(title = "签到规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MbSignRules mbSignRules) {
        List<MbSignRules> list = mbSignRulesService.selectMbSignRulesList(mbSignRules);
        ExcelUtil<MbSignRules> util = new ExcelUtil<MbSignRules>(MbSignRules.class);
        util.exportExcel(response, list, "签到规则数据");
    }

    /**
     * 获取签到规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('library:mbSignRules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(mbSignRulesService.selectMbSignRulesById(id));
    }

    /**
     * 新增签到规则
     */
    @PreAuthorize("@ss.hasPermi('library:mbSignRules:add')")
    @Log(title = "签到规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MbSignRules mbSignRules) {
        return toAjax(mbSignRulesService.insertMbSignRules(mbSignRules));
    }

    /**
     * 修改签到规则
     */
    @PreAuthorize("@ss.hasPermi('library:mbSignRules:edit')")
    @Log(title = "签到规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MbSignRules mbSignRules) {
        return toAjax(mbSignRulesService.updateMbSignRules(mbSignRules));
    }

    /**
     * 删除签到规则
     */
    @PreAuthorize("@ss.hasPermi('library:mbSignRules:remove')")
    @Log(title = "签到规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mbSignRulesService.deleteMbSignRulesByIds(ids));
    }

    /**
     * 查询字典详细
     */
    @GetMapping("/detail/{dictId}")
    public String detail(@PathVariable("dictId") Long dictId, ModelMap mmap) {
        mmap.put("signRule", mbSignRulesService.selectMbSignRulesById(dictId));
        mmap.put("signRuleList", mbSignRulesService.selectSignRulesAll());
        return prefix + "/data/data";
    }

}
